Re: [INTERFACES] libpq & user

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема Re: [INTERFACES] libpq & user
Дата
Msg-id l03110704b1d220f2ec4a@[147.233.159.109]
обсуждение исходный текст
Ответ на libpq & user  (Robert Knop <rknop@panisse.lbl.gov>)
Ответы Re: [INTERFACES] libpq & user  (Robert Knop <rknop@panisse.lbl.gov>)
Список pgsql-interfaces
At 0:02 +0300 on 15/7/98, Robert Knop wrote:


> I'm trying to use libpq to read a Postgres database from C.  I use the
> following command to connect to the database:
>
>   PGconn *deep;
>   deep=PQsetdb("dara",NULL,"user=deep",NULL,"deep");

I didn't exactly get it from your problem description, but I take it that
putting the username in the options field doesn't work.

Well, two alternatives for solution:

In the psql source code, they set the user by setting the PGUSER
environment variable. The source of the PQsetdb function states that the
following environment variables are accepted (although this is not
documented - at least not in my old 6.2.1 version):

PGHOST, PGPORT, PGTTY, PGOPTIONS, PGUSER, PGPASSWORD, PGDATABASE

So you may set these variables from within your program or from the shell
script that calls it.

Another option: the psql source, when needing a password, uses the
undocumented function:

PQconnectdb( connection_string );

The connection string is a C character string containing pairs of names and
values. For example: "host=dara user=deep password=ocean dbname=deep".

The allowed parameters are:
host, port, tty, options, user, password, authtype, dbname

Which to use? Depends on which undocumented feature you prefer... Or maybe
the gurus who actually wrote the code can give us a hint.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Ewan Mellor
Дата:
Сообщение: Non-blocking queries using libpq
Следующее
От: Byron Nikolaidis
Дата:
Сообщение: Re: [INTERFACES] [ODBC support]